package com.example.slidingexample.loader;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ViewSwitcher;

import com.example.slidingexample.R;

public class LazyAdapter extends BaseAdapter {

	private Activity activity;
	// private String[] Title,Resident,path,SubCategory;
	private static LayoutInflater inflater = null;
	public ImageLoaderSlide1 imageLoader;
	String[] mtitle;
	String[] mdist;
	String[] murl;

	public LazyAdapter(Activity a, String[] title, String[] dist, String[] url) {

		mtitle = title;
		mdist = dist;
		murl = url;

		activity = a;
		/*
		 * Title = ResTitle; Resident = ResResident; path = ResThumb;
		 * SubCategory = ResSubCate;
		 */

		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		imageLoader = new ImageLoaderSlide1(activity.getApplicationContext());
	}

	public int getCount() {
		return murl.length;
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		if (convertView == null)
			vi = inflater.inflate(R.layout.activity_item, null);

		ViewSwitcher viewswitcher_catlog = (ViewSwitcher) vi
				.findViewById(R.id.switcher);

		TextView distance = (TextView) vi.findViewById(R.id.dist);
		TextView title = (TextView) vi.findViewById(R.id.title);

		ImageView image = (ImageView) vi.findViewById(R.id.bg);
		
		distance.setText(String.format("%.2f KM", Float.parseFloat(mdist[position])));
		title.setText(mtitle[position]);

		image.setTag(position);
		imageLoader.DisplayImage(murl[position], image, viewswitcher_catlog);

		return vi;
	}
}